package com.cch.cooperation.api.zone.controller;

import com.cch.cooperation.api.auth.dto.LoginUserDTO;
import com.cch.cooperation.api.zone.dto.ZoneUserDelDTO;
import com.cch.cooperation.api.zone.dto.ZoneUserUpdateDTO;
import com.cch.cooperation.api.zone.service.ZoneUserServiceImpl;
import com.cch.cooperation.common.web.response.Response;
import com.cch.cooperation.common.web.session.Session;
import com.cch.cooperation.common.web.session.SessionManager;
import com.cch.cooperation.dao.zone.dto.ZoneUserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 空间用户接口
 *
 * @author cch
 */
@Api(tags = "空间用户接口")
@RestController
@RequestMapping("/api/zone/user")
public class ZoneUserController {

    @Resource
    private ZoneUserServiceImpl zoneUserService;
    @Resource
    private SessionManager sessionManager;

    @ApiOperation("修改")
    @PostMapping("/update")
    public Response<ZoneUserDTO> update(@RequestBody ZoneUserUpdateDTO req) {
        Session<LoginUserDTO> session = sessionManager.get();
        req.setUserId(session.getData().getId());
        ZoneUserDTO data = zoneUserService.update(req);
        return Response.success(data);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public Response<Void> delete(@RequestBody ZoneUserDelDTO req) {
        zoneUserService.delete(req);
        return Response.success();
    }

}
